package br.com.gaacorp.sai.model;

import java.io.Serializable;

import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "tab_campus")
public class Campus extends BaseObject implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2532188192512304245L;
	private Long campusId;
	private String name;
	private String description;
	private Address address = new Address();
	private College college;

	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (!(o instanceof Campus)) {
			return false;
		}

		final Campus campus = (Campus) o;

		return !(name != null ? !name.equals(campus.name) : campus.name != null);
	}

	@Embedded
	public Address getAddress() {
		return address;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getCampusId() {
		return campusId;
	}

	@ManyToOne(optional = false)
	@OnDelete(action = OnDeleteAction.CASCADE)
	public College getCollege() {
		return college;
	}

	public String getDescription() {
		return description;
	}

	public String getName() {
		return name;
	}

	public int hashCode() {
		return (name != null ? name.hashCode() : 0);
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public void setCampusId(Long campusId) {
		this.campusId = campusId;
	}

	public void setCollege(College college) {
		this.college = college;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).append(
				this.name).toString();
	}

}
